package com.yunc.oauth2.client.controller;

import com.yunc.oauth2.client.domain.dto.UserDTO;
import com.yunc.oauth2.client.feignclient.ShopFeignClient;
import com.yunc.oauth2.client.feignclient.UserFeignClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class IndexController {

    private final UserFeignClient userFeignClient;
    private final ShopFeignClient shopFeignClient;

    @GetMapping("/securedPage")
    public ModelAndView securedPage(OAuth2Authentication authentication) {
        return new ModelAndView("securedPage").addObject("authentication", authentication);
    }

    @GetMapping("/remoteCall")
    public UserDTO remoteCall() {
        UserDTO user = shopFeignClient.getUser();
        return user;
    }


}
